<?php

namespace App\Service\User;

use App\Model\CloseFriend;
use App\Model\DiscountVideoUsers;
use App\Model\UserProfile;
use App\Model\VideoCall;

/**
 * 特惠页面
 */
class DiscountVideoUserService extends UserBaseService
{
    protected $pageNum = 20;

    public function handle()
    {
        $userId = $this->getUserId();
        $page = $this->request->input('page', 1);

        $ret['list'] = [];

        $curChannel = $this->request->input('channel', '');
//        if ($curChannel == 1002) {
//            $userIds = [195939, 267641, 267623, 196239, 121, 127];
//        } else {
            if (DiscountVideoUsers::checkShowPermissions($userId) === false) {
                return $ret;
            }

            $userIds = DiscountVideoUsers::getUserList();

            $frdUserIds = CloseFriend::getFrdListLimit($userId);

            $userIds = array_diff($userIds, $frdUserIds);

            // 非正常状态女用户
            $abnormalUser = UserProfile::getAbnormalUser();
            $userIds = array_diff($userIds, $abnormalUser);

            $start = ($page - 1) * $this->pageNum;
            $userIds = array_slice($userIds, $start, $this->pageNum);
//        }

        $usersInfo = UserProfile::getUsersProfile($userIds, false, true);

        array_walk($usersInfo, function ($userProfile) use (&$ret) {
            $item = UserProfile::buildHostItem($userProfile);

            $item['is_hot'] = VideoCall::getDiscountVideTotalDay($userProfile['user_id']) >= 3 ?? false;
            $item['video_discount_coin'] = DiscountVideoUsers::DISCOUNT_COIN;

            $ret['list'][] = $item;
        });

        shuffle($ret['list']);

        return $ret;
    }
}
